<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商三方数据</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var prjLigergrid = null;
	var warnLigergrid = null;
	var _splId;
	var _warnRecId;
	var _logId;

	$(function () {
		_splId = '${splId}';
		//2020-06-09 19:51:54 三方数据关停
        <%--<c:if test="${saveBizFlowRl == 1}">
        getThreeData(1);
        </c:if>--%>
		_warnRecId = '${warnRecId}';
		var _url = '<%=path%>/spl/splhrisklog/initList.do?dataId=' + _splId + '&dataTyp=SPL';
		$("#warnLigergrid").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '类型', name:'riskTypCd', width: 240 ,
                    render: function (rowdata, rowindex, value){
                        if(rowdata.riskTypCd != null && rowdata.riskTypCd == 1){
                            return "多头" ;
                        }else if(rowdata.riskTypCd != null && rowdata.riskTypCd == 2){
                            return "涉诉/被执行";
                        }else{
                            return "";
                        }
                    }
                },
	            { display: '预警/描述', name: 'riskDesc', width: 240,
	            	render: function (rowdata, rowindex, value){
                        if(rowdata.riskTypCd != null && rowdata.riskTypCd == 1 && rowdata.riskDesc!= null){
                            return value ;
                        }else if(rowdata.riskTypCd != null && rowdata.riskDesc != null && rowdata.riskTypCd == 2){
                            if(rowdata.riskDesc == 1){
                                return '<i class="ico_flasher"></i>' + " 高风险预警";
                            }else if(rowdata.riskDesc == 0){
                                return "无高风险预警";
                            }else{
                                return "";
                            }
                        }else{
                            return "";
                        }
	            	}
	            },
	            { display: '获取时间', name: 'crtTm', width: 240,
                    render : function(rowdata, index, value){
                        return renderDate2(rowdata, index, value);
                    }
				},
				{ display: '主体属性', name: '', width: 240,
					render : function(rowdata, index, value){
						if(2== rowdata.riskTypCd && 1 == rowdata.thirdPartyCd) {
							return '企业';
						} else if(2== rowdata.riskTypCd && 2 == rowdata.thirdPartyCd){
							return '企业法人';
						}
					}
				},
	            { display: '操作', name: '', width: 240,
                    render: function (rowdata, rowindex, value){
                        if(rowdata.thirdPartyCd != null && rowdata.riskTypCd != null && rowdata.riskTypCd == 2 ){
                            return '<a class="sq-button-hasicon" href="javascript:channelRating(\''+rowdata.thirdPartyCd+'\');">报告</a>'
                        }else{
                            return "";
                        }
                    }
                },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'200',
	        heightDiff:-2,
	        rownumbers:true,
	    });
	    $("#prjLigergrid").ligerGrid({
	    	url: '<%=path%>/spl/splHRiskWarnRec/initCapChnOvdRateList.do?dataId=' + _splId + '&dataTyp=SPL',
	    	method : 'get',
	        columns: [
	            { display: '月份', align:'left',name:'ovdMonth', width: 120 },
	            { display: 'Ever(30a+&拖回)逾期',align:'left', name: 'everRate', width: 150, render: function (rowdata, rowindex, value){return value + '%';}},
	            { display: '逾期分值',align:'left', name: 'everScore', width: 120 },
	            { display: '时点（30+&拖回）逾期',align:'left', name: 'potRate', width: 150,
					render: function (rowdata, rowindex, value) {
	            		return value + '%';
					}
				},
	            { display: '时点逾期分值',align:'left', name: 'potScore', width: 120 ,
	            	render: function (rowdata, rowindex, value){
	            		     return value;
	            		}
				},
				{ display: '时间', name: 'crtTm', width: 150, render: dateRender},
				{ display: '总分值', name: 'totalScore', width: 120},
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'200',
	        heightDiff:-2,
	        rownumbers:true,
	    });
	    prjLigergrid = liger.get("prjLigergrid");
	    warnLigergrid = liger.get("warnLigergrid");
	    //grid.setHeight(100);

	    searchGroup();
	    searchOpLogSign();

	    $("#groupAndOpLog").ligerForm();
	    $("#opLogForm").ligerForm();
	    $("#searchForm").ligerForm();

	    //保存风险标记
	    $("#save").click(function(){
	    	var form = liger.get("opLogForm");
		    if (!form.valid()) {
		    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
	            return false; //验证不通过，不执行以下代码
	        }

            var isWarn = $('#isWarn').val();
            console.log(isWarn);
            if (!isWarn || !isWarn.trim()) {
                $.ligerDialog.SQalert({content: "请选择是否解除预警！" , SQ_type: "warning" });
                return false; //验证不通过，不执行以下代码
            }

		    var data = form.getData();
		    data.dataId = _splId;
		    data.bizTypCd = 'SPL';

		    //var id = $("#sId").val();
		    var url;
		    if (${isRiskWarnFlow ==1}) {
		    	data.id = _logId;
				url = '<%= path%>/spl/splRelOpLog/modify.do';
			} else {
				url = '<%= path%>/spl/splRelOpLog/add.do';
			}
			//alert(JSON.stringify(data));
	       	var wait_dialog;
		    $.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: url,
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					 wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 if(msg.data){

						 }else{

						 }
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
	    })

	    //发起复议流程
	    $("#submit").click(function(){
			var form = liger.get("opLogForm");
			if (!form.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
				return false; //验证不通过，不执行以下代码
			}

			var isWarn = $('#isWarn').val();
			console.log(isWarn);
			if (!isWarn || !isWarn.trim()) {
				$.ligerDialog.SQalert({content: "请选择是否解除预警！" , SQ_type: "warning" });
				return false; //验证不通过，不执行以下代码
			}

			var data = form.getData();
			data.dataId = _splId;
			data.bizTypCd = 'SPL';

			var wait_dialog;
	    	var flowDialog = $.ligerDialog.SQopen({
	            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp=067',
	            width: 700,
	            height:400,
	            title : '请选择要发起的流程',
	            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) {
	                        $.ligerDialog.confirm('是否确定发起评审流程?', function (flag) {
	                            if(flag == false) {
	                                return;
	                            }else{
	                                Dialog.onOk();
	                            }
	                        })
	                    }
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	            ],
	            onClose: function () {
	                var json = flowDialog._DATA;
	                console.log(json);
	                if(!json){
	                    return;
	                }
					$.ajax({
						type: 'post',
						dataType:'json',
						data:data,
						url: '<%= path%>/spl/splRelOpLog/add.do',
						beforeSend: function(){
							wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						},
						success:function(msg){
							wait_dialog.close();
							if(msg.success == 1){
								$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
								if(msg.data){
									$.ajax({
										type: 'post',
										dataType:'json',
										data:{
											id: _splId,
											procDefKey:json.procDefKey,
											procDefId:json.procDefId,
											procNo:json.procNo,
											dataTyp: 'SPL',
										},
										url: '<%=path%>/spl/splHRiskWarnRec/addFlowStart.do',
										beforeSend: function(){
											wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
										},
										success:function(msg){
											wait_dialog.close();
											if(msg.success == 1){
												$.ligerDialog.SQalert({content:msg.info, SQ_showButtons: true,SQ_type: "success",SQ_onBtnclick:function(){grid.reload();}});
												var TAB = top.mainApp.parentTab;
												var currentTabid = TAB.getSelectedTabItemID();
												try{
													var callback = GET_W2Wcallback();// currFrameElement.W2W.callback;
													callback();
												}catch(e){
													console.log(e);
												}
												top.tab.removeTabItem(currentTabid);
											}else{
												UIUtils.alertErrorHold1(msg.info);
											}
										}
									});
								}else{

								}
							}else{
								$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
							}
						}
					});
	            }
	        });
	    })
	});

	function searchGroup(){
		//查询所在集团
		$.ajax({
            type: 'get',
            dataType : 'json',
            url:'<%=path%>/splGroup/relation/getGroupBySplIdOrLnkId.do?splId='+_splId,
            success:function(msg){
                if(msg.code == 200){
                	$("#groupId").html(msg.data.id);
                	$("#groupNm").html(msg.data.name);
        			$(document).on('click','#groupNm',toGroupPage);
        			$("#groupNm").css('color','blue');
        			$("#groupNm").css('cursor','pointer');
                }else{
                	$("#groupNm").html("无");
                }
            }
        });
	}

	function dateRender(rowdata, index, value) {
		var dateStr = '';
		if (null != value && '' != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	//查询风险标记
	function searchOpLogSign(){
		$.ajax({
            type: 'get',
            dataType : 'json',
            url:'<%=path%>/spl/splRelOpLog/getById.do?dataId=' + _splId + "&bizTypCd=SPL",
            success:function(msg){
                if(msg.success == 1){
                	/*$("#isWarn").html(msg.data.isWarn);
                	$("#opTypCd").html(msg.data.opTpyCd);
                	$("#signDesc").html(msg.data.signDesc);*/
                	$("#opDesc").html(msg.data.opDesc);
					liger.get("isWarn").setValue(msg.data.isWarn);
					liger.get("isWarn").updateStyle();
					liger.get("opTypCd").setValue(msg.data.opTypCd);
					liger.get("opTypCd").updateStyle();
					liger.get("signDesc").setValue(msg.data.signDesc);
					liger.get("signDesc").updateStyle();
					_logId = msg.data.id;
                }
            }
        });
	}

	//跳转集团页面
	function toGroupPage(){
		var groupId = $("#groupId").html();
		Add_navTab('tab_group_page_' + groupId,'集团成员列表','<%=path%>/splGroup/relation/toMemberRelationList.do?groupId=' + groupId);
	}

	//打开操作日志列表
	function openOpLogList(){
        $.ligerDialog.SQopen({
            width: 800,
            height:500,
            title : '操作日志',
            url:'<%=path%>/spl/splRelOpLog/toListPage.do?dataId='+_splId+'&bizTypCd=SPL',
        });
	}

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, "yyyy-MM-dd");
        }
        return dateStr;
    }

	//打开风险报告列表
	function channelRating(data){
        if(data == 1){
            Add_navTab("toYsejdList"+_splId, "报告", '<%=path%>/riskctrl/channelRating/toYsejdListPage.do?dataId='+_splId+'&dataType=SPL');
        }else if(data == 2){
            Add_navTab("toBrcdList"+_splId, "报告", '<%=path%>/riskctrl/channelRating/toBrcdListPage.do?dataId='+_splId+'&dataType=SPL');
        };
	}

	//获取三方数据
	function getThreeData(data){
		$.ajax({
			type: 'post',
			dataType:'json',
			url: '<%=path%>/spl/splhrisklog/getSplHRiskLogS.do?dataId='+_splId+'&dataTyp=SPL',
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 if(data == 0){
                         $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 }
					//回调刷新列表
			        callback();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}

	var callback = function () {
        warnLigergrid.reload();
    };
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}

</script>

<body class="iframeBody">
		<!-- 2020-06-09 19:13:00 三方数据关停 -->
		<%--<span class="btns"><span class="sq-button sq-button-round" onclick="getThreeData(0);">获取三方数据</span></span>--%>
		<form id="groupAndOpLog">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_50">
					<div class="label">命中集团</div>
					<div class="field">
						<span id="groupId" style="display:none;">&nbsp;</span>
						<span id="groupNm">&nbsp;</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">历史记录</div>
					<div class="field">
						<a class="sq-button-hasicon" href="javascript:openOpLogList();" style="color:blue">操作记录</a>
					</div>
				</div>
			</div>
		</form>
		<c:if test="${isFlow == 1 or isWarnCheck == 1 }">
			<form id="opLogForm">
				<div class="fieldset1 tabel_col clearFix">
					<%--<c:if test="${saveBizFlowRl != 1 }">--%>
						<div class="fieldBox col_50">
							<div class="label">解除预警<span class="requiredSymbol">*</span></div>
							<div class="field">
								<select name="isWarn" id="isWarn" data-value=" ">
									<option value=" " seleted>请选择</option>
									<option value="1">持续预警</option>
									<option value="0">解除预警</option>
								</select>
							</div>
						</div>
					<%--</c:if>--%>
					<div class="fieldBox col_50">
						<div class="label">标记类型</div>
						<div class="field">
							<select name="opTypCd" id="opTypCd" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${opTypCd }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">标记原因</div>
						<div class="field">
							<select name="signDesc" id="signDesc" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${signDesc }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox col_100_auto">
						<div class="label">其他情况说明</div>
						<div class="field">
							<textarea name="opDesc" id="opDesc" rows="4"
									class="l-textarea" style="width: 99%" value=""></textarea>
						</div>
					</div>
				</div>

				<c:if test="${isRiskWarnFlow == 1 or saveBizFlowRl == 1}">
					<div class="btnsBox">
						<span id="save" class="sq-button sq-button-round">保存</span>
					</div>
				</c:if>
				<c:if test="${isRiskWarnFlow != 1 and saveBizFlowRl !=1}">
					<div class="btnsBox">
						<span id="save" class="sq-button sq-button-round">保存审核结果</span>
						<span id="submit" class="sq-button sq-button-round">有异议提交总部批示</span>
					</div>
				</c:if>
			</form>
		</c:if>
<div id="warnLigergrid" class="sq-grid"></div>
<c:if test="${isFlow != 1 and isWarnCheck != 1 }">
	<div id="prjLigergrid" class="sq-grid"></div>
</c:if>

</body>
</html>